<?php
use Illuminate\Support\Facades\DB;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

//Route::get('city', function () {
//    $items = \App\Models\PProvince::where('code', 44)->get();
//    foreach ($items as $item) {
//        $results = DB::connection('mysql_two')
//            ->table('city')
//            ->where('province_id', '=', $item['code'])
//            ->get();
//        foreach ($results as $result) {
//            $obj = new \App\Models\PCity();
//            $obj['province_id'] = $item['code'];
//            $obj['code'] = $result->city_id;
//            $obj['name'] = $result->city_name;
//            $obj->save();
//        }
//    }
//    return 'success';
//});
//
//Route::get('county', function () {
//    $items = \App\Models\PCity::where('code', 440900000000)->get();
//    foreach ($items as $item) {
//        $results = DB::connection('mysql_two')
//            ->table('county')
//            ->where('city_id', '=', $item['code'])
//            ->get();
//        foreach ($results as $result) {
//            $obj = new \App\Models\PCounty();
//            $obj['city_id'] = $item['code'];
//            $obj['code'] = $result->county_id;
//            $obj['name'] = $result->county_name;
//            $obj->save();
//        }
//    }
//    return 'success';
//});
//
//Route::get('town', function () {
//    $items = \App\Models\PCounty::all();
//    foreach ($items as $item) {
//        $results = DB::connection('mysql_two')
//            ->table('town')
//            ->where('county_id', '=', $item['code'])
//            ->get();
//        foreach ($results as $result) {
//            $obj = new \App\Models\PTown();
//            $obj['county_id'] = $item['code'];
//            $obj['code'] = $result->town_id;
//            $obj['name'] = $result->town_name;
//            $obj->save();
//        }
//    }
//    return 'success';
//});
//
//Route::get('village', function () {
//    $items = \App\Models\PTown::all();
//    foreach ($items as $item) {
//        $results = DB::connection('mysql_two')
//            ->table('village')
//            ->where('town_id', '=', $item['code'])
//            ->get();
//        foreach ($results as $result) {
//            $obj = new \App\Models\PVillage();
//            $obj['town_id'] = $item['code'];
//            $obj['code'] = $result->village_id;
//            $obj['name'] = $result->village_name;
//            $obj->save();
//        }
//    }
//    return 'success';
//});
